package com.woniu.humanresource.controller;


import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
import com.woniu.humanresource.entity.ResponseText;
import com.woniu.humanresource.entity.User;
import com.woniu.humanresource.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.swing.plaf.synth.SynthOptionPaneUI;

@CrossOrigin
@RestController
public class LoginController {
    //自动注入登录业务层
    @Autowired
    LoginService loginService;

    @PostMapping("/login")
    public ResponseText<String> login(@RequestBody User user , HttpServletResponse response, HttpServletRequest request) {

        //收到user的账号密码 业务层UserDetailServiceImpl查看数据库有没有这条数据并生成UserDetail
        //调用业务层和User Detail中的账号密码比对
        String token = loginService.login(user);
        //把token放在响应头
        response.setHeader("token", token);
        //暴露响应头
        response.setHeader("Access-Control-Expose-Headers", "token");
        return new ResponseText<>(null,200,"登录成功");

    }
}
